/*  
	------------------------------------------------------------------------
	 NQ Software Development Kit Component
	
	 Homepage: http://www.awzhome.de/
	------------------------------------------------------------------------
	
	This Source Code Form is subject to the terms of the Mozilla Public
	License, v. 2.0. If a copy of the MPL was not distributed with this
	file, You can obtain one at http://mozilla.org/MPL/2.0/.
   
	The Original Code is code of NQ Software Development Kit Component.

	The Initial Developer of the Original Code is Andreas Weizel.
	Portions created by the Initial Developer are
	Copyright (C) 2012 Andreas Weizel. All Rights Reserved.
	
	Contributor(s): (none)
	
	------------------------------------------------------------------------
*/

using AWZhome.NQ.Core;
using AWZhome.NQ.Core.Fluent;
using System;
using AWZhome.NQ.CommonServices;
using System.IO;
using System.Reflection;
using NQCSServices = AWZhome.NQ.CommonServices.Services;
using NQsdkServices = AWZhome.NQsdk.Services;

namespace AWZhome.NQsdk
{

	[NQExportedService]
	[NQServiceAttachment(CommonAttachLists.MainContainer_Startup)]
	public class SDKMenuService
	{
		private INQServiceManager servApp;
		private IResourceManager servRes;
		private IContainer servWin;

		public SDKMenuService(IContainer container)
		{
			servApp = NQServiceManager.Instance;
			servRes = ServiceCore
				.Get<NQCSServices.IResourceService>()
				.To;

			servWin = container;
			IBarManager servBar = servWin.BarService;

			// Create menu entries
			Stream xmlstream = Assembly.GetExecutingAssembly().GetManifestResourceStream("AWZhome.NQsdk.menudef.SDKMenu.xml");
			servBar.CreateItemsFromXml(xmlstream);
			xmlstream.Close();

			// Register event handlers
			servBar.ItemClicked += servBar_ItemClicked;
		}

		private void servBar_ItemClicked(object sender, BarItemClickedEventArgs e)
		{
			switch (e.Item.ItemKey)
			{
				case "SDKMenu.SystemBrowser":
					// Show the SystemBrowserView
					IView systemBrowser = ServiceCore
						.Create<NQsdkServices.ISystemBrowserViewService>()
						.DependentOn<ISession>(null)
						.To;
					systemBrowser.Initialize("");
					systemBrowser.DisplayMode = ViewDisplayMode.InClientArea;
					servWin.ViewManager.AddView(systemBrowser);
					break;

				case "SDKMenu.BarItemBrowser":
					// Show the SystemBrowserView
					IView barItemBrowser = ServiceCore
						.Create<NQsdkServices.IBarItemBrowserViewService>()
						.DependentOn<ISession>(null)
						.To;
					barItemBrowser.Initialize("");
					barItemBrowser.DisplayMode = ViewDisplayMode.InClientArea;
					servWin.ViewManager.AddView(barItemBrowser);
					break;

				case "SDKMenu.LogMessageViewer":
					// Show the SystemBrowserView
					IView logViewer = ServiceCore
						.Create<NQsdkServices.ILogMessageViewService>()
						.DependentOn<ISession>(null)
						.To;
					logViewer.Initialize("");
					logViewer.DisplayMode = ViewDisplayMode.InClientArea;
					servWin.ViewManager.AddView(logViewer);
					break;

				case "SDKMenu.LogTest":
					// TEST: Create some log messages
					ServiceCore.Log.From(this).Debug("Test debug message");
					ServiceCore.Log.From(this).Info("Test info message");
					ServiceCore.Log.From(this).Warning("Test warning message");
					ServiceCore.Log.From(this).Error("Test error message");
					break;
			}
		}
	}

}